
/**
 * 本地数据保存
 */

export default class LocalStorageData {

    private static instance: LocalStorageData = null;

    public static Instance(): LocalStorageData {
        if (this.instance == null) {
            this.instance = new LocalStorageData();
        }
        return this.instance;
    }

    private GameUserData: any = {
        id: 0,
        name: '666',
        head: '',
        gold: 0,
        astronaut: 0,
        vibration: 1,
    };

    setUserData() {
        localStorage.setItem("GameUserData", JSON.stringify(this.GameUserData));
    }

    getUserData() {
        let GameUserData = localStorage.getItem("GameUserData");
        if (GameUserData) {
            this.GameUserData = GameUserData;
        }
    }

    setTypeData(type: string, data: any) {
        this.GameUserData[type] = data;
        this.setUserData();
    }

    getTypeData(type: string) {
        return this.GameUserData[type];
    }

}
